<template>
  <div class="profile-container">
    <el-header class="header-fixed">
      <navigation />
    </el-header>
    
    <div class="content-wrapper">
      <div class="content-header">
        <div class="header-left">
          <h2 class="title">我的作品</h2>
          <span class="work-count">{{ Material.length }} 个作品</span>
          <div class="filter-tags">
            <span class="tag active">全部</span>
            <span class="tag">最新发布</span>
            <span class="tag">最多播放</span>
            <span class="tag">最多点赞</span>
          </div>
        </div>
        <div class="header-right">
          <div class="search-box">
            <i class="el-icon-search"></i>
            <input type="text" placeholder="搜索作品...">
          </div>
          <div class="view-switch">
            <span class="switch-item active" title="网格视图">
              <i class="el-icon-menu"></i>
            </span>
            <span class="switch-item" title="列表视图">
              <i class="el-icon-s-grid"></i>
            </span>
          </div>
          <button class="upload-btn">
            <i class="el-icon-upload2"></i>
            上传作品
          </button>
        </div>
      </div>

      <div class="category-nav">
        <span v-for="cat in categories" 
              :key="cat.name"
              :class="['nav-item', { active: activeCategory === cat.name }]"
              @click="changeCategory(cat.name)">
          {{ cat.name }}
          <span class="category-count" v-if="cat.count > 0">({{ cat.count }})</span>
        </span>
      </div>

      <div class="filter-tags">
        <span v-for="tag in filterTags"
              :key="tag.key"
              :class="['tag', { active: activeFilter === tag.name }]"
              @click="changeFilter(tag.name)">
          {{ tag.name }}
        </span>
      </div>

      <div class="content-section">
        <div v-if="Material.length === 0" class="empty-state">
          <div class="empty-animation">
            <i class="el-icon-picture-outline"></i>
            <div class="animation-circle"></div>
          </div>
          <h3>开始创作你的第一个作品</h3>
          <p>让创意绽放光彩</p>
          <div class="empty-actions">
            <button class="create-btn">
              <span class="btn-icon">+</span>
              <span>创建作品</span>
            </button>
            <button class="import-btn">
              <i class="el-icon-download"></i>
              导入作品
            </button>
          </div>
          <div class="quick-tips">
            <div class="tip-item">
              <i class="el-icon-video-camera"></i>
              <span>支持视频上传</span>
            </div>
            <div class="tip-item">
              <i class="el-icon-picture"></i>
              <span>支持图片上传</span>
            </div>
            <div class="tip-item">
              <i class="el-icon-document"></i>
              <span>支持文档上传</span>
            </div>
          </div>
        </div>
        
        <div v-else class="content-masonry">
          <div v-for="(item, index) in Material" 
               :key="index" 
               class="content-card"
               @click="goLoadDetails(item.id, item.name)">
            <div class="card-image">
              <img :src="item.cover" :alt="item.name">
              <div class="card-overlay">
                <div class="overlay-content">
                  <div class="overlay-icon">
                    <i class="el-icon-view"></i>
                  </div>
                  <div class="overlay-stats">
                    <span class="stat-item">
                      <i class="el-icon-star-off"></i>
                      <span>0</span>
                    </span>
                    <span class="stat-item">
                      <i class="el-icon-chat-dot-round"></i>
                      <span>0</span>
                    </span>
                  </div>
                </div>
              </div>
              <div class="card-badge" v-if="index < 3">
                <i class="el-icon-trophy"></i>
                <span>Top {{ index + 1 }}</span>
              </div>
            </div>
            <div class="card-info">
              <div class="info-header">
                <h3>{{ item.name }}</h3>
                <div class="status-tag">已发布</div>
              </div>
              <div class="info-meta">
                <span class="meta-date">
                  <i class="el-icon-time"></i>
                  {{ new Date().toLocaleDateString() }}
                </span>
                <span class="meta-category">
                  <i class="el-icon-folder"></i>
                  视频
                </span>
                <span class="meta-duration">
                  <i class="el-icon-video-camera"></i>
                  03:24
                </span>
              </div>
              <div class="progress-bar">
                <div class="progress" style="width: 75%"></div>
                <span class="progress-text">播放量 75%</span>
              </div>
            </div>
            <div class="card-actions">
              <button class="action-btn edit" title="编辑">
                <i class="el-icon-edit"></i>
              </button>
              <button class="action-btn share" title="分享">
                <i class="el-icon-share"></i>
              </button>
              <button class="action-btn more" 
                      title="更多选项"
                      @click="toggleMenu(index, $event)">
                <i class="el-icon-more"></i>
              </button>
            </div>
            <div class="card-menu" v-show="showMenu === index">
              <div class="menu-item" @click="handleMenuAction('edit', item, $event)">
                <i class="el-icon-edit-outline"></i>
                <span>编辑信息</span>
              </div>
              <div class="menu-item" @click="handleMenuAction('share', item, $event)">
                <i class="el-icon-share"></i>
                <span>分享</span>
              </div>
              <div class="menu-item" @click="handleMenuAction('download', item, $event)">
                <i class="el-icon-download"></i>
                <span>下载</span>
              </div>
              <div class="menu-item delete" @click="handleMenuAction('delete', item, $event)">
                <i class="el-icon-delete"></i>
                <span>删除</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="pagination">
        <button class="page-btn prev">
          <i class="el-icon-arrow-left"></i>
        </button>
        <div class="page-numbers">
          <span class="page active">1</span>
          <span class="page">2</span>
          <span class="page">3</span>
          <span class="page-dots">...</span>
          <span class="page">10</span>
        </div>
        <button class="page-btn next">
          <i class="el-icon-arrow-right"></i>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup>
import navigation from '@/components/navigation.vue';
import { ref, onMounted } from 'vue';
import request from '@/utils/request';
import { useRouter } from 'vue-router';

const router = useRouter();
const Material = ref([]);
const userName = localStorage.getItem('userName');
const activeCategory = ref('全部分类');
const activeFilter = ref('全部');

// 分类数据
const categories = [
  { name: '全部分类', count: 0 },
  { name: '剧情', count: 0 },
  { name: '动作', count: 0 },
  { name: '喜剧', count: 0 },
  { name: '爱情', count: 0 },
  { name: '科幻', count: 0 },
  { name: '动画', count: 0 }
];

// 过滤标签
const filterTags = [
  { name: '全部', key: 'all' },
  { name: '最新发布', key: 'latest' },
  { name: '最多播放', key: 'most_played' },
  { name: '最多点赞', key: 'most_liked' }
];

// 切换分类
const changeCategory = (category) => {
  activeCategory.value = category;
  // 这里可以调用接口重新获取数据
  PersonalMaterial(userName, category);
};

// 切换过滤器
const changeFilter = (filter) => {
  activeFilter.value = filter;
  // 这里可以调用接口重新获取数据
  PersonalMaterial(userName, activeCategory.value, filter);
};

const PersonalMaterial = async (userName, category = '全部分类', filter = '全部') => {
  const res = await request.get('/details/personalMaterial', { 
    params: { 
      username: userName,
      category: category,
      filter: filter
    } 
  });
  Material.value = res.data.data;
};

const goLoadDetails = async (id, name) => {
  router.push({ name: 'VideoStory', params: { id: id, name: name } });
};

// 显示/隐藏菜单
const showMenu = ref(-1);
const toggleMenu = (index, event) => {
  event.stopPropagation();
  showMenu.value = showMenu.value === index ? -1 : index;
};

// 菜单操作
const handleMenuAction = (action, item, event) => {
  event.stopPropagation();
  switch(action) {
    case 'edit':
      console.log('编辑', item);
      break;
    case 'share':
      console.log('分享', item);
      break;
    case 'download':
      console.log('下载', item);
      break;
    case 'delete':
      console.log('删除', item);
      break;
  }
  showMenu.value = -1;
};

onMounted(() => {
  PersonalMaterial(userName);
});
</script>

<style scoped>
.profile-container {
  min-height: 100vh;
  background-color: #f4f5f7;
}

.header-fixed {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 1000;
  background: white;
  border-bottom: 1px solid #eee;
}

.content-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 80px 20px 40px;
}

.content-header {
  margin-bottom: 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title {
  font-size: 28px;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0;
}

.work-count {
  color: #666;
  font-size: 14px;
  background: #f0f0f0;
  padding: 4px 12px;
  border-radius: 20px;
}

.view-switch {
  display: flex;
  background: #f0f0f0;
  padding: 4px;
  border-radius: 8px;
  gap: 4px;
}

.switch-item {
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.switch-item.active {
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.switch-item i {
  font-size: 18px;
  color: #666;
}

.content-section {
  min-height: 400px;
}

.content-masonry {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 20px;
}

.content-card {
  border-radius: 12px;
  background: white;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.content-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 24px rgba(0,0,0,0.12);
}

.card-image {
  position: relative;
  padding-top: 140%;
  overflow: hidden;
}

.card-image img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.content-card:hover .card-image img {
  transform: scale(1.05);
}

.card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, 
    rgba(0,0,0,0.2) 0%,
    rgba(0,0,0,0.5) 50%,
    rgba(0,0,0,0.8) 100%);
  opacity: 0;
  transition: all 0.3s ease;
  display: flex;
  align-items: flex-end;
  padding: 20px;
}

.content-card:hover .card-overlay {
  opacity: 1;
}

.overlay-content {
  width: 100%;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.content-card:hover .overlay-content {
  transform: translateY(0);
}

.overlay-icon {
  width: 44px;
  height: 44px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  backdrop-filter: blur(4px);
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.overlay-icon i {
  font-size: 20px;
  color: white;
}

.overlay-stats {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.stat-item {
  color: white;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.stat-item i {
  font-size: 16px;
  color: rgba(255, 255, 255, 0.9);
}

.card-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  background: linear-gradient(45deg, #ff6b6b, #feca57);
  color: white;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(255, 107, 107, 0.3);
  z-index: 2;
}

.card-badge i {
  font-size: 14px;
}

.card-info {
  padding: 16px;
  background: white;
  border-top: 1px solid #f0f0f0;
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.info-header h3 {
  color: #1a1a1a;
  font-size: 15px;
  margin: 0;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 12px;
}

.status-tag {
  font-size: 12px;
  color: #00b894;
  background: rgba(0, 184, 148, 0.1);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.info-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12px;
  color: #666;
  margin-bottom: 12px;
}

.meta-date, .meta-category, .meta-duration {
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.meta-date i, .meta-category i, .meta-duration i {
  font-size: 14px;
}

.progress-bar {
  height: 4px;
  background: #f0f0f0;
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.progress {
  height: 100%;
  background: linear-gradient(90deg, #3b41c5, #a981bb);
  border-radius: 2px;
  transition: width 0.6s ease;
}

.progress-text {
  position: absolute;
  right: 0;
  top: -20px;
  font-size: 12px;
  color: #666;
}

.card-actions {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 10px;
  opacity: 0;
  transform: translateX(10px);
  transition: all 0.3s ease;
  z-index: 3;
}

.content-card:hover .card-actions {
  opacity: 1;
  transform: translateX(0);
}

.action-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.action-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

.action-btn i {
  font-size: 18px;
  color: white;
}

.card-menu {
  position: absolute;
  top: 48px;
  right: 8px;
  background: rgba(0, 0, 0, 0.9);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  padding: 6px 0;
  min-width: 140px;
  z-index: 100;
}

.menu-item {
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
}

.menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.menu-item i {
  font-size: 16px;
  width: 16px;
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
}

.menu-item.delete {
  color: #ff6b6b;
}

.menu-item.delete:hover {
  background: rgba(255, 107, 107, 0.1);
}

.menu-item.delete i {
  color: #ff6b6b;
}

.filter-tags {
  display: flex;
  gap: 8px;
  margin-left: 20px;
}

.tag {
  padding: 4px 12px;
  border-radius: 16px;
  font-size: 13px;
  color: #666;
  background: #f0f0f0;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tag:hover {
  background: #e0e0e0;
}

.tag.active {
  background: #3b41c5;
  color: white;
}

.search-box {
  display: flex;
  align-items: center;
  background: #f5f5f5;
  border-radius: 8px;
  padding: 8px 16px;
  margin-right: 16px;
}

.search-box i {
  color: #999;
  margin-right: 8px;
}

.search-box input {
  border: none;
  background: none;
  outline: none;
  font-size: 14px;
  width: 200px;
}

.upload-btn {
  background: #3b41c5;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
}

.upload-btn:hover {
  background: #2d31a6;
  transform: translateY(-2px);
}

.category-nav {
  display: flex;
  gap: 24px;
  margin-bottom: 30px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.category-nav::-webkit-scrollbar {
  display: none;
}

.nav-item {
  font-size: 15px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  position: relative;
}

.nav-item:hover {
  color: #3b41c5;
}

.nav-item.active {
  color: #3b41c5;
  font-weight: 500;
}

.nav-item.active::after {
  content: '';
  position: absolute;
  bottom: -16px;
  left: 0;
  right: 0;
  height: 3px;
  background: #3b41c5;
  border-radius: 3px;
}

.category-count {
  font-size: 12px;
  color: #999;
  margin-left: 4px;
}

.empty-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 32px;
}

.import-btn {
  background: #f5f5f5;
  color: #666;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.import-btn:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

.quick-tips {
  display: flex;
  justify-content: center;
  gap: 32px;
}

.tip-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  font-size: 14px;
}

.tip-item i {
  font-size: 20px;
  color: #3b41c5;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 40px;
  gap: 16px;
}

.page-numbers {
  display: flex;
  gap: 8px;
}

.page {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
}

.page:hover {
  background: #f0f0f0;
}

.page.active {
  background: #3b41c5;
  color: white;
}

.page-dots {
  color: #666;
  display: flex;
  align-items: center;
}

.page-btn {
  width: 32px;
  height: 32px;
  border: 1px solid #eee;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  background: white;
}

.page-btn:hover {
  border-color: #3b41c5;
  color: #3b41c5;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

@media (max-width: 768px) {
  .filter-tags, .search-box {
    display: none;
  }
  
  .header-right {
    gap: 8px;
  }
  
  .upload-btn span {
    display: none;
  }
  
  .category-nav {
    gap: 16px;
    margin-bottom: 20px;
  }
  
  .quick-tips {
    flex-direction: column;
    gap: 16px;
    align-items: center;
  }
}

.action-btn.more {
  background: rgba(0, 0, 0, 0.6);
  width: 36px;
  height: 36px;
}

.action-btn.more i {
  font-size: 20px;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.action-btn.more i::before {
  content: "•••";
  letter-spacing: 2px;
  font-size: 18px;
  font-weight: bold;
}

.action-btn.more:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* 修改其他按钮样式以保持一致 */
.action-btn.edit, .action-btn.share {
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.6);
}

.action-btn.edit i, .action-btn.share i {
  font-size: 18px;
}

.action-btn.edit:hover, .action-btn.share:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* 添加按钮提示文本 */
.action-btn::after {
  content: attr(title);
  position: absolute;
  bottom: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.action-btn:hover::after {
  opacity: 1;
  visibility: visible;
  bottom: -35px;
}
</style>
  